<template>
	<view class="back-view" @touchmove.stop.prevent="moveHandle">
		<view class="view-background"></view>
		<view class="white-view-back">
			<view class="top-back">
				<view class="top-name">选择案件</view>
				<view class="close-back" @click="closeBtnAction">
					<image class="close-img" src="../../../static/close.png"></image>
				</view>
			</view>
			<view class="top-line"></view>
			<scroll-view style="height: 390px;" scroll-y="true">
				<view class="item-back" v-for="(item,index) in dataList" :key="index">
					<view class="item-img-back" @click="clickSelectAction(item,index)">
						<image class="item-img"
							:src="item.isSel?'../../../static/selected_circle.png':'../../../static/select_circle.png'">
						</image>
					</view>
					<view class="item-item-back">
						<view class="item-top-back">
							<image class="item-top-img" src="../../../static/phone/phone_case_list_img.png"></image>
							<view class="item-name">{{item.custName}}</view>
							<view class="item-num">编号: {{item.no}}</view>
						</view>
						<view class="item-content">
							{{item.content}}
						</view>
						<view class="item-status">状态<text
								class="item-status-des">{{item.status.code=='4' ? item.bizStatus : item.status.desc}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
			<view class="bottom-back">
				<view class="bottom-btn" @click="clickCustomerAction">确认</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {

		},
		data() {
			return {
				role: '',
				roleUrl: '',
				dataList: [],
				tabIndex: -1,
			}
		},
		onLoad() {

		},
		mounted() {
			console.log('查询案件')
			this.role = getApp().globalData.role
			this.roleUrl = this.$roleUrl({
				tab: this.role
			})
			this.getList()
		},
		methods: {
			async getList() {

				let _this = this
				uni.showToast({
					title: '正在查询...',
					icon: 'loading'
				})
				const res = await _this.$myRequest({
					url: `/${_this.roleUrl}/case/selector/`,
					method: 'POST',
					data: {
						page: 1,
						size: 1000
					}
				})
				uni.hideLoading()
				console.log('案件列表', res)
				if (res.data.code == 200) {
					_this.dataList = []
					let list = res.data.data
					for (var i = 0; i < list.length; i++) {
						list[i]['isSel'] = false
						_this.dataList.push(list[i])
					}
				} else {
					uni.showToast({
						title: '查询失败，请重试!',
						icon: "error"
					})
				}
			},

			clickSelectAction(item, index) {
				let _this = this
				if (_this.dataList[index]['isSel']) {
					_this.dataList[index]['isSel'] = !_this.dataList[index]['isSel']
					_this.tabIndex = -1
				} else {
					for (var i = 0; i < _this.dataList.length; i++) {
						if (index === i) {
							_this.dataList[i]['isSel'] = true
							_this.tabIndex = index
						} else {
							_this.dataList[i]['isSel'] = false
						}
					}
				}
			},
			closeBtnAction() {
				this.$emit('caseSelectClose')
			},
			moveHandle() {
				return true
			},
			clickCustomerAction() {
				let _this = this
				if (_this.tabIndex == -1) {
					uni.showToast({
						title: '请选择所属案件',
						icon: "none",
						duration: 1500
					})

				} else {
					//保存数据 返回
					let item = _this.dataList[_this.tabIndex]
					this.$emit('clickCustomerAction',item)
					
				}
			},

		},
	}
</script>

<style>
	.back-view {
		position: fixed;
		top: 0;
		right: 0;
		bottom: 0;
		left: 0;
		z-index: 99;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.view-background {
		position: absolute;
		width: 100%;
		height: 100%;
		z-index: 100;
		background-color: rgba(0, 0, 0, 0.3);
	}

	.white-view-back {
		width: 552px;
		height: 500px;
		padding: 24px;
		max-height: 500px;
		background-color: white;
		margin-top: -50px;
		border-radius: 4px;
		z-index: 101;
		position: absolute;
	}

	.top-back {
		display: flex;
		justify-content: space-between;
	}

	.top-name {
		font-size: 18px;
		font-weight: normal;
		color: #333333;

	}

	.close-back {
		cursor: pointer;
		width: 20px;
		height: 20px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.close-img {
		width: 12px;
		height: 12px;
	}

	.top-line {
		height: 1px;
		background: #EEEEEE;
		width: 100%;
		margin-top: 20px;
		margin-bottom: 20px;
	}

	.bottom-back {

		bottom: 0px;
		width: 100%;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: absolute;
		height: 60px;
		right: 16px;
	}

	.bottom-btn {
		cursor: pointer;
		width: 104px;
		height: 32px;
		background: #2DA9C5;
		border-radius: 2px;
		color: #FFFFFF;
		font-size: 14px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.item-back {

		width: 100%;
		display: flex;
		align-items: center;
	}

	.item-img-back {
		width: 24px;
		height: 24px;
		display: flex;
		align-items: center;
	}

	.item-img {
		width: 12px;
		height: 12px;
		min-width: 12px;
	}

	.item-item-back {
		border-radius: 2px;
		border: 1px solid #EEEEEE;
		width: 508px;
		padding: 10px 16px;
		margin-bottom: 10px;
	}

	.item-top-back {
		display: flex;
		align-items: center;
	}

	.item-top-img {
		width: 24px;
		height: 24px;
	}

	.item-name {
		font-size: 12px;
		font-weight: 400;
		color: #333333;
		margin-left: 6px;
	}

	.item-num {
		font-size: 12px;
		font-weight: 400;
		color: #999999;
		margin-right: 0px;
		margin-left: auto;
	}

	.item-content {
		font-size: 14px;
		font-weight: 400;
		color: #333333;
		margin-top: 8px;
	}

	.item-status {
		font-size: 12px;
		font-weight: 400;
		color: #333333;
		margin-top: 8px;

	}

	.item-status-des {
		color: #2DA9C5;
		margin-left: 2px;
	}
</style>
